﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a source resource for an embedded object.
    /// </summary>
    [Standalone]
    [Serializable]
    public class Source : Element {
        private string _src;
        private string _type;
        private string _media;

        /// <summary>
        /// Constructs a Source element with the given URL.
        /// </summary>
        public Source(string src) {
            _src = src;
        }

        /// <summary>
        /// Constructs a Source element with the given URL an MIME type.
        /// </summary>
        /// <param name="src">The URL of the target media.</param>
        /// <param name="type">The MIME type of the target media.</param>
        public Source(string src, string type) {
            _src = src;
            _type = type;
        }

        /// <summary>
        /// Determines the URL of this source.
        /// </summary>
        public string Src {
            get { return _src; }
            set { _src = value; }
        }

        /// <summary>
        /// Determines the MIME type for this source.
        /// </summary>
        public string Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Determines the media query for this source.
        /// </summary>
        public string Media {
            get { return _media; }
            set { _media = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _media, "media");
            AttributeWriter.Write(sb, _src, "src");
            AttributeWriter.Write(sb, _type, "type");
        }
    }
}
